package com.xiaoma.tpo.dao;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;

import com.xiaoma.tpo.baseDao.BaseDaoImpl;
import com.xiaoma.tpo.baseDao.DefaultRowMapper;
import com.xiaoma.tpo.domain.WdGroup;
import com.xiaoma.tpo.dto.WdGroupVo;

@Repository
public class WdGroupDao extends BaseDaoImpl<WdGroup>{

private static final Logger LOG = LoggerFactory.getLogger(WdGroupDao.class);
    
    @SuppressWarnings("unchecked")
    public List<WdGroupVo> findWordGroupsByPlanId(int planId){
        String sql = "select a.id, a.name, a.seq_num, a.wd_plan_id plan_id, a.audio_zip, count(a.id) word_count from wd_group a left join wd_group_word b on a.id = b.wd_group_id group by a.id having a.wd_plan_id = ?";
        LOG.info("SQL:{} planId:{}", sql, planId);
        List<?> reslut = jdbcTemplate.query(sql, new DefaultRowMapper(WdGroupVo.class, getNameHandler()), planId);
        return (List<WdGroupVo>)reslut;
    }
}
